home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2617 < prev    next >
Encoding:
Text File  |  1996-08-06  |  13.0 KB  |  344 lines

  1. Path: Portugal.EU.net!alce!Joe.Buck
  2. From: Joe.Buck@alce.pt (Joe Buck)
  3. Newsgroups: comp.lang.c++
  4. Subject: (2/2) FAQ for g++ and libg++, texinfo version [Revised 15 Jan 1996]
  5. Message-ID: <17D20191@alce.pt>
  6. Date: Mon, 15 Jan 96 14:00:11 GMT
  7. Organization: Associacao Lusa de Correio Electronico
  8.  
  9. You may be running into a bug that was introduced in version 2.6.1
  10. (and is still present in 2.6.3) that generated external linkage
  11. for templates even when neither @code{-fexternal-templates} nor
  12. @code{-fno-implicit-templates} is specified.  There is a patch for
  13. this problem at @*
  14. @file{ftp://ftp.cygnus.com/pub/g++/gcc-2.6.3-template-fix}.
  15.  
  16. I recommend either applying the patch or
  17. using @code{-fno-implicit-templates}
  18. together with explicit template instantiation as described in previous
  19. sections.
  20.  
  21. This bug is fixed in 2.7.0.
  22.  
  23. @node Standard Template Library, agreement with standards, redundant
  24. templates, User Problems
  25. @section Does g++ support the Standard Template Library?
  26.  
  27. From Per Bothner:
  28.  
  29. @cindex STL
  30. @cindex Standard Template Library
  31. The Standard Template Library (STL) uses many of the extensions that the
  32. ANSI/ISO committee has made to templates, and g++ doesn't support
  33. some of these yet.  So if you grab HP's free implementation of STL it
  34. isn't going to work.  However, libg++-2.6.2 contains a
  35. hacked version of STL, based on work by Carsten Bormann, which permits
  36. gcc-2.6.3 to compile at least the containers.  A full implementation is
  37. going to need improved template support, which will take a while yet.
  38.  
  39. As of libg++-2.7.0 and gcc-2.7.0, I've succeeded in making many short
  40. STL example programs work, though there are still a number of bugs
  41. and limitations.  Almost all of the ObjectSpace examples (a set of
  42. over 200 simple examples of STL usage) now work.
  43.  
  44. There are several commercial suppliers of STL implementations;
  45. ObjectSpace's version supports gcc-2.7.x.
  46.  
  47. Mumit Khan has produced an ``STL newbie guide'' with lots of information
  48. on using STL with gcc.  See
  49.  
  50. @file{http://www.xraylith.wisc.edu/~khan/software/stl/STL.newbie.html}
  51.  
  52. @node agreement with standards, compiling standard libraries, Standard
  53. Template Library, User Problems
  54. @section What are the differences between g++ and the ARM specification of
  55. C++?
  56.  
  57. @cindex ARM [Annotated C++ Ref Manual]
  58. @cindex exceptions
  59. As of version 2.7.0, g++ has exception support on most but not all
  60. platforms
  61. (no support on MIPS-based platforms yet), but
  62. it doesn't work right if optimizaton is enabled, which means the
  63. exception
  64. implementation is still
  65. not really ready for production use.
  66.  
  67.  
  68. @cindex mutable
  69. Some features that the ANSI/ISO standardization committee has voted in
  70. that don't appear in the ARM are supported, notably the @code{mutable}
  71. keyword, in version 2.5.x.  2.6.x adds support for the built-in boolean
  72. type @code{bool}, with constants @code{true} and @code{false}.  The
  73. beginnings of run-time type identification are present, so there are
  74. more reserved words: @code{typeid}, @code{static_cast},
  75. @code{reinterpret_cast}, @code{const_cast}, and @code{dynamic_cast}.
  76.  
  77. @cindex g++ bugs
  78. As with any beta-test compiler, there are bugs.  You can help improve
  79. the compiler by submitting detailed bug reports.
  80.  
  81. One of the weakest areas of g++ other than templates is the resolution
  82. of overloaded functions and operators in complex cases.  The usual
  83. symptom is that in a case where the ARM says that it is ambiguous which
  84. function should be chosen, g++ chooses one (often the first one
  85. declared).  This is usually not a problem when porting C++ code from
  86. other compilers to g++, but shows up as errors when code developed under
  87. g++ is ported to other compilers.  (I believe this is no longer a
  88. significant problem in 2.7.0).
  89.  
  90. [A full bug list would be very long indeed, so I won't put one here.
  91. I may add a list of frequently-reported bugs and "non-bugs" like the
  92. static class members issue mentioned above].
  93.  
  94. @node compiling standard libraries, debugging on SVR4 systems, agreement
  95. with standards, User Problems
  96. @section Will g++ compile InterViews?  The NIH class library?  Rogue Wave?
  97.  
  98. @cindex NIH class library
  99. @cindex NIHCL with g++
  100. The NIH class library uses a non-portable, compiler-dependent hack
  101. to initialize itself, which makes life difficult for g++ users.
  102. It will not work without modification, and I don't know what modifications
  103. are required or whether anyone has done them successfully.
  104.  
  105. In short, it's not going to happen any time soon (previous FAQs referred
  106. to patches that a new NIHCL release would hopefully contain, but this
  107. hasn't happened).
  108.  
  109. @strong{Note:} I thought I saw an item indicating that someone
  110. @emph{had} patched NIHCL to work with g++.  Any pointers?
  111.  
  112. @cindex InterViews
  113. I think that as of version 2.5.6, the standard g++ will compile the
  114. standard 3.1 InterViews completely successfully.
  115. Note that you'll need the @code{-fno-for-scope} flag
  116. if you use gcc-2.7.0; with 2.7.2 you may be able to omit this flag
  117. but you'll get warnings.
  118.  
  119. @cindex Rogue Wave
  120. According to Jason Merrill, the latest g++ (2.7.0) works with Rogue
  121. Wave's @code{tools.h++} class library, but you may want to grab
  122. @file{ftp://ftp.cygnus.com/pub/g++/Tools.h++-6.1-patch}.  Again,
  123. you'll need the @code{-fno-for-scope} flag since Rogue Wave hasn't
  124. fixed their code to comply with the new standard yet.
  125.  
  126. @node debugging on SVR4 systems, X11 conflicts with libg++, compiling
  127. standard libraries, User Problems
  128. @section Debugging on SVR4 systems
  129. @cindex System VR4, debugging
  130.  
  131. ``How do I get debugging to work on my System V Release 4 system?''
  132.  
  133. Most systems based on System V Release 4 (except Solaris) encode symbolic
  134. debugging information in a format known as `DWARF'.
  135.  
  136. Although the GNU C compiler already knows how to write out symbolic
  137. debugging
  138. information in the DWARF format, the GNU C++ compiler does not yet have
  139. this
  140. feature, nor is it likely to in the immediate future.
  141.  
  142. Ron Guilmette has done a great deal of work to try to get the GNU C++
  143. compiler
  144. to produce DWARF format symbolic debugging information (for C++ code)
  145. but he gave up on the project because of a lack of funding and/or interest
  146. from the g++ user community.  If you have a strong desire to see this
  147. project
  148. completed, contact Ron at <rfg@@netcom.com>.
  149.  
  150. In the meantime, you @emph{can} get g++ debugging under SVR4 systems by
  151. configuring gcc with the @code{--with-stabs} option.  This causes gcc to
  152. use an alternate debugging format, one more like that used under SunOS4.
  153. You won't need to do anything special to GDB; it will always understand
  154. the ``stabs'' format.
  155.  
  156. @node X11 conflicts with libg++, assignment to streams, debugging on SVR4
  157. systems, User Problems
  158. @section X11 conflicts with libg++ in definition of String
  159. @cindex String, conflicts in definition
  160.  
  161. ``X11 and Motif define String, and this conflicts with the String class
  162. in libg++.  How can I use both together?''
  163.  
  164. One possible method is the following:
  165.  
  166. @example
  167. #define String XString
  168. #include <X11/Intrinsic.h>
  169. /* include other X11 and Motif headers */
  170. #undef String
  171. @end example
  172.  
  173. and remember to use the correct @code{String} or @code{XString} when
  174. you declare things later.
  175.  
  176. @node assignment to streams, ,X11 conflicts with libg++, User Problems
  177. @section Why can't I assign one stream to another?
  178.  
  179. [ Thanks to Per Bothner and Jerry Schwarz for this section. ]
  180.  
  181. Assigning one stream to another seems like a reasonable thing to do, but
  182. it's a bad idea.  Usually, this comes up because people want to assign
  183. to @code{cout}.  This is poor style, especially for libraries, and is
  184. contrary to good object-oriented design.  (Libraries that write directly
  185. to @code{cout} are less flexible, modular, and object-oriented).
  186.  
  187. The iostream classes do not allow assigning to arbitrary streams, because
  188. this can violate typing:
  189.  
  190. @example
  191. ifstream foo ("foo");
  192. istrstream str(...);
  193. foo = str;
  194. foo->close ();  /* Oops! Not defined for istrstream! */
  195. @end example
  196.  
  197. @cindex assignment to cout
  198.  
  199. The original cfront implementation of iostreams by Jerry Schwarz allows
  200. you to assign to @code{cin}, @code{cout}, @code{cerr}, and @code{clog},
  201. but this is not part of the draft standard for iostreams and generally
  202. isn't considered a good idea, so standard-conforming code shouldn't use
  203. this technique.
  204.  
  205. The GNU implementation of iostream did not support assigning to 
  206. @code{cin}, @code{cout}, @code{cerr}, and @code{clog}
  207. for quite a while, but it now does, for backward
  208. compatibility with cfront iostream (versions 2.6.1 and later of libg++).
  209.  
  210. The ANSI/ISO C++ Working Paper does provide ways of changing the
  211. streambuf associated with a stream.  Assignment isn't allowed;
  212. there is an explicit named member that must be used.
  213.  
  214. However, it is not wise to do this, and the results are confusing.  For
  215. example: @code{fstream::rdbuf} is supposed to return the @emph{original}
  216. filebuf, not the one you assigned. (This is not yet implemented in GNU
  217. iostream.)  This must be so because @code{fstream::rdbuf} is defined to
  218. return a @code{filebuf *}.
  219.  
  220. @node legalities, index, User Problems, Top
  221. @chapter What are the rules for shipping code built with g++ and libg++?
  222. @cindex Shipping rules
  223. @cindex GPL [GNU Public License]
  224.  
  225. ``Is it is possible to distribute programs for profit that are created
  226. with g++ and use the g++ libraries?''
  227.  
  228. I am not a lawyer, and this is not legal advice.  In any case, I have
  229. little interest in telling people how to violate the spirit of the
  230. GNU licenses without violating the letter.  This section tells you
  231. how to comply with the intention of the GNU licenses as best I understand
  232. them.
  233.  
  234. @cindex FSF [Free Software Foundation]
  235. The FSF has no objection to your making money.  Its only interest is that
  236. source code to their programs, and libraries, and to modified versions of
  237. their programs and libraries, is always available.
  238.  
  239. The short answer is that you do not need to release the source to
  240. your program, but you can't just ship a stripped executable either,
  241. unless you use only the subset of libg++ that includes the iostreams
  242. classes (see discussion below) or the new libstdc++ library (available
  243. in libg++ 2.6.2 and later).
  244.  
  245. Compiling your code with a GNU compiler does not affect its copyright;
  246. it is still yours.  However, in order to ship code that links in a GNU
  247. library such as libg++ there are certain rules you must follow.  The
  248. rules are described in the file COPYING.LIB that accompanies gcc
  249. distributions; it is also included in the libg++ distribution.
  250. See that file for the exact rules.  The agreement is called the
  251. Library GNU Public License or LGPL.  It is much "looser" than the
  252. GNU Public License, or GPL, that covers must GNU programs.
  253.  
  254. @cindex libg++, shipping code
  255. Here's the deal: let's say that you use some version of libg++,
  256. completely unchanged, in your software, and you want to ship only
  257. a binary form of your code.  You can do this, but there are several
  258. special requirements.  If you want to use libg++ but ship only object
  259. code for your code, you have to ship source for libg++ (or ensure
  260. somehow that your customer already has the source for the exact
  261. version you are using), and ship your application in linkable form.
  262. You cannot forbid your customer from reverse-engineering or extending
  263. your program by exploiting its linkable form.
  264.  
  265. @cindex libg++, modifying
  266. Furthermore, if you modify libg++ itself, you must provide source
  267. for your modifications (making a derived class does not count as
  268. modifying the library -- that is "a work that uses the library").
  269.  
  270. @cindex special copying conditions for iostreams
  271. For certain portions of libg++ that implement required parts of the C++
  272. language (such as iostreams and other standard classes), the FSF has
  273. loosened the copyright requirement still more by adding the ``special
  274. exception'' clause, which reads as follows:
  275.  
  276. @quotation
  277. As a special exception, if you link this library with files
  278. compiled with GCC to produce an executable, this does not cause
  279. the resulting executable to be covered by the GNU General Public License.
  280. This exception does not however invalidate any other reasons why
  281. the extion I get undefined symbols when using templates
  282.  
  283. (Thanks to Jason Merrill for this section).
  284.  
  285. @cindex template instantiation
  286. g++ does not automatically instantiate templates defined in other files.
  287. Because of this, code written for cfront will often produce undefined
  288. symbol errors when compiled with g++.  You need to tell g++ which template
  289. instances you want, by explicitly instantiating them in the file where
  290. they
  291. are defined.  For instance, given the files
  292.  
  293. @file{templates.h}:
  294. @example
  295. template <class T>
  296. class A @{
  297. public:
  298.   void f ();
  299.   T t;
  300. @};
  301.  
  302. template <class T> void g (T a);
  303. @end example
  304.  
  305. @file{templates.cc}:
  306. @example
  307. #include "templates.h"
  308.  
  309. template <class T>
  310. void A<T>::f () @{ @}
  311.  
  312. template <class T>
  313. void g (T a) @{ @}
  314. @end example
  315.  
  316.  
  317. main.cc:
  318. @example
  319. #include "templates.h"
  320.  
  321. main ()
  322. @{
  323.   A<int> a;
  324.   a.f ();
  325.   g (a);
  326. @}
  327. @end example
  328.  
  329. compiling everything with @code{g++ main.cc templates.cc} will result in
  330. undefined symbol errors for @samp{A<int>::f ()} and @samp{g (A<int>)}.  To
  331. fix these errors, add the lines
  332.  
  333. @example
  334. template class A<int>;
  335. template void g (A<int>);
  336. @end example
  337.  
  338. to the bottom of @samp{templates.cc} and recompile.
  339.  
  340. @node redundant templates, Standard Template Library, undefined templates,
  341. User Problems
  342. @section I get multiply defined symbols using templates
  343.  
  344.